from contextvars import ContextVar
from typing import Any, Dict

__registry: Dict[str, ContextVar] = {}


def register_var(name: str, default: Any = None) -> None:
    if name not in __registry:
        __registry[name] = ContextVar(name, default=default)


def set_var(name: str, value: Any) -> None:
    if name not in __registry:
        register_var(name)
    __registry[name].set(value)


def get_var(name: str, default: Any = None) -> Any:
    var = __registry.get(name)
    return var.get() if var else default


def reset_var(name: str) -> None:
    if name in __registry:
        __registry[name].set(None)
